<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户角色查询</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .container { margin-top: 30px; }
        .result-card { margin-top: 20px; }
    </style>
</head>
<body>
<div class="container">
    <h2>任务一：查询用户及其拥有的所有角色</h2>
    <!-- 面包屑导航 -->
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="/">首页</a></li>
            <li class="breadcrumb-item active" aria-current="page">用户角色查询</li>
        </ol>
    </nav>

    <!-- 查询表单 -->
    <div class="card">
        <div class="card-body">
            <form method="post" action="/user/queryWithRoles">
                <div class="mb-3">
                    <label for="username" class="form-label">用户名</label>
                    <input type="text" class="form-control" id="username" name="username"
                           placeholder="请输入用户名（如admin、jack）" required>
                </div>
                <button type="submit" class="btn btn-primary">查询</button>
            </form>
        </div>
    </div>

    <!-- 查询结果展示（查询后显示） -->
    <div th:if="${user != null}" class="result-card card">
        <!-- 用户信息卡片 -->
        <div class="card-header bg-primary text-white">
            <h5 class="mb-0">用户信息</h5>
        </div>
        <div class="card-body">
            <h5 class="card-title" th:text="${'用户名：' + user.loginname}"></h5>
            <p class="card-text" th:text="${'姓名：' + user.name}"></p>
            <p class="card-text" th:text="${'邮箱：' + (user.email != null ? user.email : '未设置')}"></p>
            <p class="card-text" th:text="${'状态：' + (user.status == 0 ? '正常' : '禁用')}"></p>
        </div>

        <!-- 角色列表卡片 -->
        <div class="card-header bg-secondary text-white">
            <h5 class="mb-0">拥有的角色</h5>
        </div>
        <div class="card-body">
            <div th:if="${user.roles == null or user.roles.isEmpty()}">
                <p class="text-muted">该用户未分配任何角色</p>
            </div>
            <ul class="list-group" th:unless="${user.roles == null or user.roles.isEmpty()}">
                <li class="list-group-item" th:each="role : ${user.roles}"
                    th:text="${role.name + ' - ' + (role.description != null ? role.description : '无描述')}">
                    角色名称 - 角色描述
                </li>
            </ul>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>